#!/usr/bin/env python

from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.orm.shard import ShardedSession
from sqlalchemy.sql import operators
from sqlalchemy import sql
import datetime

#db_papa_basic = create_engine( 'mysql://root:123456@localhost/papa_basic' )
db_papa_datas = {}
for i in range(10):
	db_papa_datas[str(i)] = create_engine( 'mysql://root:123456@localhost/papa_data_%d' % i )

create_session = sessionmaker(class_=ShardedSession)
create_session.configure(shards=db_papa_datas)

meta=MetaData()

t_user = Table('t_user', meta,
	Column('uid', String(32), nullable=False, primary_key=True ),
	Column('name', String(32), nullable=False),
	Column('mobile', String(32), nullable=True),
	Column('login_time', DateTime),
)

t_shop = Table('t_shop', meta,
	Column('uid', String(32), nullable=False, primary_key=True ),
	Column('visit', Integer, nullable=False),
)


def rebuild_all_tables():
	for db in db_papa_datas.values():
		meta.drop_all(db)
		meta.create_all(db)


